﻿package ;

import asc.Client;
import asc.io.File;
import asc.io.FileInput;
import haxe.BaseCode;
import haxe.io.Bytes;
import haxe.Serializer;
import haxe.Unserializer;
import js.Lib;

/**
 * ...
 * @author waneck
 */

class Main 
{
	
	static function main() 
	{
		Lib.application.onAppStart = myMain;
	}
	
	static function myMain()
	{
		Lib.application.onConnect = clientConnect;
		Lib.application.allowDebug = true;
	}
	
	static private function clientConnect(client:Client, ?p1:Dynamic, ?p2:Dynamic, ?p3:Dynamic, ?p4:Dynamic, ?p5:Dynamic, ?p6:Dynamic, ?p7:Dynamic):Bool
	{
		client.getImage = function(location:String)
		{
			var f = File.getBytes(location);
			trace("file length " + f.length);
			return Serializer.run(f);
		}
		
		client.setImage = function(b:String)
		{
			var f = File.write("test.jpg", true);
			var b:Bytes = Unserializer.run(b);
			f.writeBytes(b, 0, b.length);
			f.close();
			trace("image received and saved at test.jpg");
		}
		return true;
	}
	
}